<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>极简弹幕</title>
  <style>
    :root {
      --theme: #4e73ff;
    }
    * {
      box-sizing: border-box;
    }
    body {
      margin: 0;
      font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
      background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
      height: 100vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      color: #e0e0ff;
    }
    /* 弹幕舞台 */
    #stage {
      position: relative;
      flex: 1;
      width: 100%;
      overflow: hidden;
      cursor: crosshair;
    }
    /* 单条弹幕 */
    .dm {
      position: absolute;
      white-space: nowrap;
      font-size: 22px;
      font-weight: 600;
      color: #fff;
      text-shadow: 0 0 4px var(--theme), 0 0 8px rgba(0, 0, 0, 0.7);
      animation: scroll 10s linear forwards;
      user-select: none;
      line-height: 1;
      padding: 4px 0;
    }
    @keyframes scroll {
      from {
        transform: translateX(100vw);
      }
      to {
        transform: translateX(-100%);
      }
    }
    /* 底部控制栏 */
    .bar {
      background: rgba(255, 255, 255, 0.08);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      border-top: 1px solid rgba(255, 255, 255, 0.1);
      padding: 14px 20px;
      display: flex;
      gap: 12px;
      align-items: center;
      box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.2);
    }
    .bar input {
      flex: 1;
      padding: 10px 14px;
      background: rgba(0, 0, 0, 0.2);
      border: 1px solid rgba(255, 255, 255, 0.1);
      border-radius: 8px;
      font-size: 15px;
      color: #ffffff;
      transition: all 0.3s;
    }
    .bar input:focus {
      outline: none;
      border-color: var(--theme);
      box-shadow: 0 0 0 3px rgba(78, 115, 255, 0.2);
    }
    .bar button {
      padding: 10px 18px;
      border: none;
      border-radius: 8px;
      font-size: 15px;
      cursor: pointer;
      transition: all 0.3s;
      white-space: nowrap;
      background: var(--theme);
      color: #fff;
      box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    }
    .bar button:hover {
      filter: brightness(1.1);
      transform: translateY(-2px);
      box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
    }
    .bar button:active {
      transform: translateY(0);
    }
    /* 彩色文字按钮 */
    .colorful {
      background: linear-gradient(45deg, #ff6b9d, #ffb74d, #4ecdc4);
      background-size: 400% 400%;
      animation: gradient 4s ease infinite;
    }
    @keyframes gradient {
      0% { background-position: 0% 50%; }
      50% { background-position: 100% 50%; }
      100% { background-position: 0% 50%; }
    }
    /* 小屏幕适配 */
    @media (max-width: 480px) {
      .dm {
        font-size: 18px;
      }
      .bar {
        flex-wrap: wrap;
      }
    }
  </style>
</head>

<body>
  <!-- 弹幕区域 -->
  <div id="stage"></div>

  <!-- 控制栏 -->
  <div class="bar">
    <input id="textInput" type="text" placeholder="输入弹幕内容，回车发送" maxlength="40">
    <button onclick="send()">发送</button>
    <button class="colorful" onclick="colorful()">彩虹弹幕</button>
    <button onclick="clearDM()">清屏</button>
  </div>

  <script>
    const stage = document.getElementById('stage');
    const colors = ['#ff6b9d', '#ffb74d', '#4ecdc4', '#a855f7', '#00d1e0', '#ffc107'];

    // 发送弹幕
    function send(txt) {
      const text = txt || document.getElementById('textInput').value.trim();
      if (!text) return;

      const span = document.createElement('span');
      span.className = 'dm';
      span.textContent = text;
      // 随机颜色
      span.style.color = colors[Math.floor(Math.random() * colors.length)];
      // 随机轨道（垂直位置）
      const h = stage.clientHeight;
      const top = Math.random() * (h - 30);
      span.style.top = top + 'px';

      stage.appendChild(span);

      // 动画结束后移除
      span.addEventListener('animationend', () => span.remove());
      // 清空输入框
      if (!txt) document.getElementById('textInput').value = '';
    }

    // 彩虹弹幕
    function colorful() {
      const text = document.getElementById('textInput').value.trim() || '彩虹弹幕';
      // 每个字不同颜色
      const rainbow = text.split('').map((c, i) => `<span style="color:${colors[i % colors.length]}">${c}</span>`).join('');
      const span = document.createElement('span');
      span.className = 'dm';
      span.innerHTML = rainbow;
      const h = stage.clientHeight;
      span.style.top = Math.random() * (h - 30) + 'px';
      stage.appendChild(span);
      span.addEventListener('animationend', () => span.remove());
      document.getElementById('textInput').value = '';
    }

    // 清屏
    function clearDM() {
      stage.innerHTML = '';
    }

    // 回车发送
    document.getElementById('textInput').addEventListener('keydown', e => {
      if (e.key === 'Enter') send();
    });

    // 点击屏幕快速发送
    stage.addEventListener('click', e => {
      const txt = prompt('快速发送弹幕：');
      if (txt) send(txt);
    });

    // 定时随机弹幕（演示）
    setInterval(() => {
      const demos = ['Hello', '极简弹幕', '好酷', '🎉', '666', 'javascript', 'CSS动画', 'Web开发'];
      send(demos[Math.floor(Math.random() * demos.length)]);
    }, 3000);
  </script>
</body>
</html>